<%@page import="com.kh.pajx.sop.util.common.FormatDate"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<%
	String path = request.getContextPath();
	String temp_str = FormatDate.getUseDate(new Date());
%>
<script type="text/javascript">
function allCheck(check) {//全选
   　var checkbox=document.getElementsByName("cost");
        if(check.checked){
				for(var i=0;i<checkbox.length;i++){
　						checkbox[i].checked="checked";
               }
		}else{
               for(var i=0;i<checkbox.length;i++){
　						checkbox[i].checked="";
				} 
		}  
}
  $(document).ready(function(){
	  $("#PayManageId").val('${saleId}'); 
  });
	  function payBalance(uuid,code,state){
		  alertMsg.confirm("确定要签批吗？", {
				okCall : function() {
		  var  url="foreign_oneApproveBalanceAppPay.action";
		  data={
				  "model.uuid":uuid,
				  "model.appType":state,
				  "model.billState":3,
				  "billCode":code
		  }
		  $.ajax({ 
			  url: url, 
			  type:"post",
			  data :data,
			  dataType:"json",
			  success: function(message){
				  navTabAjaxDone(message);
		      }});
				}})
	  };
	  function showTr(sid,state){
			var tr ="";
			var whichEl = document.getElementById("tr" + sid);
			var datalist=$("#balanceAppPayManageList"+sid);
			datalist.empty();
			if (whichEl.style.display == "none") {
				if(state==1){
					var data={"foreign.appBillCode":sid};
					var url="foreign_findForeignList.action";
			$.post(url,data,function(message){
				var list=message;
				var str=list.split(";");
				for ( var i = 0; i < str.length-1; i++) {
					tr+="<tr>";
					var str1=str[i].split(",");
					for ( var j = 2; j< str1.length-1; j++) {
						if(j==10||j==12||j==14||j==16){
							tr+="<td><span style='color:red'>"
								 +str1[j]
								  +"</span></td>";
						}else{
						tr+="<td>"
						 +str1[j]
						  +"</span></td>";
					  }
					}
					tr+="</tr>";
				}
				   datalist.append(tr);
				   whichEl.style.display = "";
				   initRemoveAllNode(sid);
			      })
				}else{
					var data={"areaManger.appBillCode":sid};
					var url="foreign_findAreaMangerList.action";
					$.post(url,data,function(message){
						var list=message;
						var str=list.split(";");
						for ( var i = 0; i < str.length-1; i++) {
							tr+="<tr>";
							var str1=str[i].split(",");
							for ( var j = 2; j< str1.length-1; j++) {
								if(j==11){
									tr+="<td><span style='color:red'>"
										 +str1[j]
										  +"</span></td>";
								}else{
								tr+="<td>"
								 +str1[j]
								  +"</span></td>";
							  }
							}
							tr+="</tr>";
						}
						datalist.append(tr);
						whichEl.style.display = "";
						initRemoveAllNode(sid);
					})
				}
			}else{
				 initRemoveNode(sid);
			}
		}
		function  initRemoveNode(sid){
			var whichEl = document.getElementById("tr" + sid);
			whichEl.style.display = "none";
		}
		function  initRemoveAllNode(sid){
			　var whichEl=document.getElementsByName("tr_code");
					for(var i=0;i<whichEl.length;i++){
						if(whichEl[i].value!=sid){
							var tr= document.getElementById("tr" + whichEl[i].value);
							if(tr.style.display = "none"){
							}else{
						   tr.style.display = "none";
						     $("#tr" + whichEl[i].value).empty();
							}
						}
					}
			 };
			 function deleteForeign() {
				 var deleteTr=$("#tablepaymanage tr.selected").attr('deleteTr');
				 if(typeof(deleteTr) != "undefined"){
						var id=deleteTr.split(",")[0];
						var code=deleteTr.split(",")[1];
				 alertMsg.confirm("确定要撤销吗？", {
						okCall : function() {
					var data = {
							"model.uuid":id,
							"foreign.appBillCode":code
					};
					var url = "foreign_updateBalanceApp.action";
					 $.ajax({ 
						  url: url, 
						  type:"post",
						  data :data,
						  dataType:"json",
						  success: function(message){
							  navTabAjaxDone(message);
					      }});
			 }})
				 }else{
						alertMsg.info("请选择一条记录");
					}
				};
</script>
<div class="pageHeader">
	<form id="pagerForm" method="post" action="foreign_balanceAppPayManageList.action">
	<input type="hidden" name="pageNum" value="${currentPage}" />
	<input type="hidden" name="numPerPage" value="${numPerPage}" />
	<input type="hidden"  value="${teaNo}" name="saleId">
	</form>
				<form onsubmit="return navTabSearch(this);" action="foreign_balanceAppPayManageList.action" method="post" >
			<div class="searchBar nowrap">
			<p><label>部&nbsp;&nbsp;门：</label><select name="deptCode" id="deptCode" class="combox" ref="PayManageId"
														refUrl="school_getAllSaler.action?deptCode={value}">
									<option value="">---所有部门---</option>
									<c:forEach items="${deptList}" var="dept">
										<option ${deptCode==dept.deptCode?"selected":""} value="${dept.deptCode}">${dept.deptName}</option>
									</c:forEach>
							</select>
				</p>
				<p><label>销售人员</label>
							<select name="saleId" id="PayManageId"
								class="required combox">
									<option value="">---请选择---</option>
							</select>
				</p>
			<div class="subBar" float="left">
				<ul>
					<li>
					<div class="buttonActive" ><div class="buttonContent"><button type="submit">检索</button></div></div>
					</li>
				</ul>
			</div>
		</div>
			</form>
		</div>
<div class="pageContent">
	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="add" href="javascript:void(0)" onclick="deleteForeign()"><span>撤销</span></a></li>
			<li class="line">line</li>
			
		</ul>             
	</div>
			<table class="list" width="100%" layoutH="96" id="tablepaymanage">
				<thead>
					<tr>
						<!-- <th><input type='checkbox' onclick='allCheck(this)'
							checked="checked" /></th> -->
						<th>申请单号</th>
						<th>申请类型</th>
						<th>申请人</th>
						<th>申请金额</th>
						<th>申请日期</th>
						<th>审批人</th>
						<th>审批日期</th>
						<th>审批金额</th>
						<th>状态</th>
					</tr>
				</thead>

				<tbody>
					<c:forEach items="${recordList}" var="fb" varStatus="countStatus">
						<tr id="row${fb.uuid}" deleteTr="${fb.uuid},${fb.appBillCode}">
							<td ><a href="javascript:void(0)" onclick="showTr('${fb.appBillCode}','${fb.appType}')">${fb.appBillCode}</a></td>
							<td>
							<c:if test="${fb.appType==1}">对外结算</c:if>
							<c:if test="${fb.appType==2}">行业经理</c:if>
							</td>
							<td>
							<c:if test="${!empty fb.appPerson}">
							<script>
							 var url="foreign_findUser.action?timestamp="+ new Date().getTime();
							 var data={saleId:'${fb.appPerson}'};
								$.post(url,data,function(message){
									var msg=message;
									$("#balanceAppPayManageList_appperson_"+${countStatus.count}).text(msg);
								})
							 </script>
							 <span id="balanceAppPayManageList_appperson_${countStatus.count}"></span>
							 </c:if>
							</td>
							<td>${fb.appSumFee}</td>
						<td><f:parseDate value="${fb.appDate}"
									pattern="yyyyMMddHHmm" var="test" /> <f:formatDate
									value="${test}" pattern="yyyy-MM-dd HH:mm" />
						</td>
						<td>
						<c:if test="${!empty fb.chkPerson}">
						<script>
							 var url="foreign_findUser.action?timestamp="+ new Date().getTime();
							 var data={saleId:'${fb.chkPerson}'};
								$.post(url,data,function(message){
									var msg=message;
									$("#balanceAppPayManageList_checkperson_"+${countStatus.count}).text(msg);
								})
							 </script>
							 <span id="balanceAppPayManageList_checkperson_${countStatus.count}"></span>
							 </c:if>
						</td>
						<td><f:parseDate value="${fb.chkDate}"
									pattern="yyyyMMddHHmm" var="test" /> <f:formatDate
									value="${test}" pattern="yyyy-MM-dd HH:mm" />
						</td>
						<td>${fb.chkMoney}</td>
						<td>已签批<input name="tr_code"  value="${fb.appBillCode}"  type="hidden"/></td>
						</tr>
                       <tr  id='tr${fb.appBillCode}' style="display: none" >
                       <td colspan="9">
                       <table id='table1'  class="list" width="100%">
                       <thead>
                       <c:if test="${fb.appType==1}">
                        <tr >
                       <th rowspan="2">学校名称</th>
                       <th rowspan="2">结算日期</th>
						<th rowspan="2">总人数</th>
						<th colspan="4" style="text-align:center">有效用户数</th>
						<th colspan="2" style="text-align:center">客户经理结算</th>
						<th colspan="2" style="text-align:center">学校现金返还</th>
						<th colspan="2" style="text-align:center">学校话费返还</th>
						<th colspan="2" style="text-align:center">管理员费用</th>
						<th rowspan="2">备注</th>
                       </tr>
                       <tr>
                       	<th>本期</th>
                       	<th>上期</th>
                       	<th>新增</th>
                       	<th>开通率</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	</tr>
                       	</c:if>
                       	 <c:if test="${fb.appType==2}">
                        <tr >
                       <th rowspan="2">地区名称</th>
                       <th rowspan="2">结算日期</th>
                       <th rowspan="2">学校数量</th>
						<th rowspan="2">总人数</th>
						<th colspan="4" style="text-align:center">有效用户数</th>
						<th colspan="2" style="text-align:center">行业经理结算</th>
						<th rowspan="2">备注</th>
                       </tr>
                       <tr>
                       	<th>本期</th>
                       	<th>上期</th>
                       	<th>新增</th>
                       	<th>开通率</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	</tr>
                       	</c:if>
                       </thead>
				      <tbody id="balanceAppPayManageList${fb.appBillCode}">
				      </tbody>
                       </table>
                       </td>
                       </tr>
					</c:forEach>
				</tbody>

			</table>
		</div>
<%@ include file="/WEB-INF/jsp/public/panelBar.jsp"%>
